; THIS IS A PROGRAM TO SYSGEN A CP/M SYSTEM ON SD OR DD DISKS UESING
; MYDDBIOS.Z80 BIOS
;		JOHN J MONAHAN		VERSION	0.0	4/10/81
;
PROM:	EQU	0F800H
;
;THIS SYSTEM WILL BE SIMILAR TO THE ORIGINAL
;THE USER WILL BE ASKED IF HE WANTS TO COPY THE FIRST TWO TRACKS
;FROM DISK A: OR FROM WHAT IS IN MEMORY ALREADY.
;THEN HE WILL BE ASKED IF HE WANTS IT TO GO TO DISK B: OR STAY IN MEMORY
;
;SET DMA TO 900H
;SET TO DRIVE A FOR DENSITY
;SET TO TRACK 0, SECTOR 1
;READ 2 TRACKS FROM DISK 1	(USEING MYDDBIOS.Z80 ROM)
;ASK USER IF HE WANTS TO COPY TO DISK B OR TO LEAVE
;IF LEAVE END
;OTHERWISE
;SET DMA BACK TO 900H
;SET TO DRIVE B FOR CORRECT DENSITY
;SET TO TRACK 0, SECTOR 1
;WRITE 2 TRACKS TO DISK 2
;
;
;EQUATE TABLE FOR BDOS
CONSTAT:EQU	11
CONIN:	EQU	1
CONOUT:	EQU	2
PRINTBUF:EQU	9
BDOS:	EQU	5
;
	ORG	100H
START:	LD	HL,0
	ADD	HL,SP
	LD	(OLDSTACK),HL
	LD	SP,NEWSTACK
SAVEOD:	LD	A,(42H)
	LD	(OLDDRIVE),A ;SAVE CURRENT DRIVE TYPE
	LD	A,(53H)
	LD	(OLDCOUNT),A ;SAVE CURRENT SECTORS/TRACK
	
QUESTION:LD	DE,MSG11     ;WANT MEMORY OR DISKTRACK
	LD	C,PRINTBUF
	CALL	BDOS
	LD	C,CONIN	     ;GET THE ANSWER FROM KEYBOARD
	CALL	BDOS
	AND	5FH	     ;CHANGE TO UPPER CASE ONLY
	CP	'M'
	JP	Z,QUEST2
	CP	'D'
	JP	Z,DISKA
	CP	'S'
	JP	Z,DISKC
	JP	EXIT
;
DISKA:	LD	A,40H	     ;SET UNIT BYTE TO DRIVE A IN DOUBLE DENSITY
	LD	(42H),A
	LD	A,32H	     ;SET TO 50 SECTORS/TRACK
	LD	(53H),A
	JP	DISKLOAD
DISKC:	LD	A,0H	     ;SET UNIT BYTE TO DRIVE A IN SINGLE DENSITY
	LD	(42H),A
	LD	A,1AH	     ;SET TO 26 SECTORS/TRACK
	LD	(53H),A
;
DISKLOAD:
SETDMA:	LD	HL,900H
	LD	(40H),HL
SETSEC:	LD	A,1
	LD	(43H),A
SETTRK:	LD	A,0
	LD	(44H),A
SECN:	LD	A,52	     ;NUMBER OF SECTORS TO READ
	LD	(45H),A
READ:	CALL	PROM+39H     ;NOTE DIFFERENCE FROM STANDARD SD ROM--------
	JP	NZ,ERROR     ;IF NON ZERO THEN PROBLEM
;
;GETS HERE WITH MEMORY AT 900H CONTAINING THE SYSTEM
;
QUEST2:	LD	DE,MSG12     ;DO YOU WANT TO LEAVE OR TO WRITE TO B
	LD	C,PRINTBUF
	CALL	BDOS
	LD	C,CONIN
	CALL	BDOS
	AND	5FH
	CP	'D'
	JP	Z,WRITB
	CP	'S'
	JP	Z,WRITD
	JP	EXIT
;NOW WRITE TO THE DISK SELECTED
WRITB:	LD	A,41H	     ;FOR B: DOUBLE DENSITY
	LD	(42H),A
	LD	A,32H	     ;50 SECTORS/TRACK
	LD	(53H),A
	JP	SETD
WRITD:	LD	A,1H	     ;FOR D:SINGLE DENSITY
	LD	(42H),A
	LD	A,1AH	     ;26 SECTORS/TRACK
	LD	(53H),A 
SETD:	LD	HL,900H
	LD	(40H),HL
SETS:	LD	A,1
	LD	(43H),A
SETT:	LD	A,0
	LD	(44H),A
SN:	LD	A,52	     ;NUMBER OF SECTORS TO WRITE
	LD	(45H),A
WRITE:	CALL	PROM+36H     ;NOTE DIFFERENCE FROM SD PROM-------
	JP	NZ,ERROR
	JP	QUEST2
;
EXIT:	LD	A,(OLDDRIVE)	
	LD	(42H),A
	LD	A,(OLDCOUNT)
	LD	(53H),A
	LD	HL,(OLDSTACK)
	LD	SP,HL
	JP	0H
;
ERROR:	LD	DE,MSG10
	LD	C,PRINTBUF
	CALL	BDOS
	JP	0H
;
	DEFS	40	     ;SPACE FOR NEWSTACK
NEWSTACK:DEFS	2
OLDSTACK:DEFS	2
OLDDRIVE:DEFS	1
OLDCOUNT:DEFS	1
MSG10:	DEFB	0AH,0DH,'Error in disk data',0DH,0AH,'$'
MSG11:	DEFB	0AH,0AH,0DH,'If system is from a DOUBLE density disk enter  D'
	DEFB	0AH,0DH,'If system is from a SINGLE density disk enter  S'
	DEFB	0AH,0DH,'If system is already in RAM @ 900H enter   M'
	DEFB	0AH,0DH,'Enter CR to quit  $'
MSG12:	DEFB	0AH,0AH,0DH,'Enter D or S for density of destination drive'   
	DEFB	0AH,0DH,'Enter CR to quit $'
;END
